package fsoft.com.vn.directory.controller;


import java.util.Map;

import fsoft.com.vn.directory.form.Contact;
import fsoft.com.vn.directory.service.ContactService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class ContactController {

	@Autowired
	private ContactService contactService;

	@RequestMapping("/contact")
	public String listContacts(Map<String, Object> map) {

		map.put("contact", new Contact());
		map.put("contactList", contactService.listContact());

		return "contact";
	}
	
	

	//@RequestMapping(value = "/add", method = RequestMethod.POST)
	//public String addContact(@ModelAttribute("contact") Contact contact,
	//		BindingResult result) {

	//	contactService.addContact(contact);

	//	return "redirect:/index";
	//}

	//@RequestMapping("/delete/{contactId}")
	//public String deleteContact(@PathVariable("contactId") Integer contactId) {

	//	contactService.removeContact(contactId);

	//	return "redirect:/index";
	//}
	
	@RequestMapping("/searchContact")
	public String search(Map<String, Object>map, @RequestParam(value = "firstname") String Firstname, @RequestParam(value = "surname") String Surname){
		map.put("contact", new Contact());
		map.put("contactList", contactService.search(Firstname, Surname));
		return "contact";
		
	}
	
}

